package com.bytefy.server.sandbox;

import java.util.HashMap;
import java.util.Map;

public class Session {
	private Map<String, String> data = new HashMap<String, String>();
	public static Session instance;
	
	static {
		instance = new Session();
	}

	public String get(String key) {
		synchronized (key.intern()) {
			if (!data.containsKey(key)) return null;
			return data.get(key);
		}
	}
	
	public void set(String key, String value) {
		synchronized (key.intern()) { 
			data.put(key, value);
		}
	}
	
	public double increment(String key, double af) {
		synchronized (key.intern()) {
			String keyv = get(key);
			Double value = new Double(keyv==null?"0":keyv);
			double last = value;
			value += af;
			set(key, value.toString());
			return last;
		}
	}
}
